<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Enable Phoenix development site</title>
        <link rel="stylesheet" href="styles.css" />
        <script>
            function showDebugStatuses(localStorageKey, descriptionID, buttonID) {
                let enabled = localStorage.getItem(localStorageKey) === "true",
                    statusMessage = `Debug logs for ${localStorageKey} are currently Disabled`,
                    btnMessage = `Enable debug logs for ${localStorageKey}`,
                    color = "red";
                if(enabled){
                    statusMessage = `Debug logs for ${localStorageKey} are currently Enabled`;
                    btnMessage = `Disable debug logs for ${localStorageKey}`;
                    color = "green";
                }

                document.getElementById(descriptionID).textContent = statusMessage;
                document.getElementById(descriptionID).style.color = color;
                document.getElementById(buttonID).textContent = btnMessage;
            }

            function showEnabledStatus() {
                let enabled = localStorage.getItem("devDomainsEnabled") === "true",
                    statusMessage = `Dev site at ${location.hostname} is currently Disabled`,
                    btnMessage = `Enable ${location.hostname}`,
                    color = "red";
                if(enabled){
                    statusMessage = `Dev site at ${location.hostname} is currently Enabled`;
                    btnMessage = `Disable ${location.hostname}`;
                    color = "green";
                }
                document.getElementById("heading").textContent = `Enable or Disable Phoenix Development site at: ${location.hostname}`;
                document.getElementById("enableStatus").textContent = statusMessage;
                document.getElementById('enableStatus').style.color = color;
                document.getElementById("enableBtn").textContent = btnMessage;
                showDebugStatuses("logToConsole", "enableStatusDebugLogs", "enableBtnDebugLogs");
                showDebugStatuses("logLivePreview", "enableStatusDebugLivePreview", "enableBtnDebugLivePreview");
            }
            function toggleLocalStorageItem(key) {
                let enabled = localStorage.getItem(key) === "true";
                enabled = "" + (!enabled);
                localStorage.setItem(key, enabled);
                showEnabledStatus();
            }
        </script>
    </head>
    <body onload="showEnabledStatus()">
        <h1 id="heading">Enable or Disable Phoenix Dev site.</h1>
        <div id="enableStatus">Checking if dev site is enabled...</div>
        <br />
        <button id="enableBtn" onclick="toggleLocalStorageItem('devDomainsEnabled')">Click me</button>

        <h2>Enable or disable debug logs.</h2>
        <div id="enableStatusDebugLogs">Checking if debug logs are enabled...</div>
        <br />
        <button id="enableBtnDebugLogs" onclick="toggleLocalStorageItem('logToConsole')">Click me</button>

        <h2>Enable or disable debug live preview logs.</h2>
        <div id="enableStatusDebugLivePreview">Checking if debug logs are enabled...</div>
        <br />
        <button id="enableBtnDebugLivePreview" onclick="toggleLocalStorageItem('logLivePreview')">Click me</button>
    </body>
</html>
